package com.example.recycler.scroller;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private S_ViewGroup mSViewGroup;
    private float start,now;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mSViewGroup = (S_ViewGroup) findViewById(R.id.activity_main);
        final DensityUtil densityUtil=new DensityUtil(this);
        mSViewGroup.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){

                    case MotionEvent.ACTION_DOWN:
                        start=event.getX();
                        break;
                    case MotionEvent.ACTION_MOVE:

                        now=event.getX();

                        mSViewGroup.scrollBy(-(int) (densityUtil.dip2px(300)*((now-start)/densityUtil.getScreenWidth())),0);
                        System.out.println("xx "+densityUtil.dip2px(300)*((now-start)/densityUtil.getScreenWidth()));
                        break;
                }
                return true;
            }
        });
    }

    public void go(View view){
        Toast.makeText(this, "滚一下", Toast.LENGTH_SHORT).show();
//        mActivityMain2.scrollTo(300,0);
//        Scroller scroller=new Scroller(this);
//        scroller.startScroll();

        mSViewGroup.beginScroll();
    }
}
